<?php
namespace app\common\model;

class BonusMemberDaily extends Base
{
	protected $insert =['create_time'];
	protected $auto = ['update_time'];

	protected function setCreateTimeAttr(){
		return time();
	}

	protected function setUpdateTimeAttr(){
		return time();
	}

	/**
	 * 累计某日奖金
	 * @param  [type] $uid        [description]
	 * @param  [type] $day        [description]
	 * @param  [type] $bonus_name [description]
	 * @param  [type] $inc_amount [description]
	 * @return [type]             [description]
	 */
	public function incDayBonus($uid,$day,$bonus_name,$inc_amount){
		// 如果该会员该日该奖金存在记录，累加，否则插入
		$where = ['uid'=>$uid,'day'=>$day,'bonus_name'=>$bonus_name];
		if($this->where($where)->find()){
			$this->where($where)->setInc('total',$inc_amount);
		}else{
			$this->save([
				'uid'=>$uid,
				'day'=>$day,
				'bonus_name'=>$bonus_name,
				'total'=>$inc_amount
			]);
		}
		return true;
	}

}
